<%@ page language="java" %>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.utils.StringUtils"%>
<%@ page import="java.util.Calendar" %>
<%@ page import="com.scalar.chiptrack.utils.WorkWeek" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<html:html >
<HEAD>
<TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
    <style type="text/css" media="print">
    @page
    {
        size: landscape;
        margin: 2cm;
    }
    </style>
</HEAD>
<logic:present name="wipFlush" scope="session">
<BODY TOPMARGIN=0>
<TABLE BORDER="0" align="center" width="100%">
    <TR>
        <TD WIDTH="90%" VALIGN="CENTER" ALIGN="CENTER" CLASS="NArialW">Wip Flush - <%=request.getParameter("heading")%> Report By Vendor <%=request.getParameter ( "holdHeading" )%></TD>
        <TD WIDTH="5%" VALIGN="CENTER" >
            <A HREF="javascript:window.print();" TITLE='Click to Print wip flush'><IMG HEIGHT="60" WIDTH="60" SRC="<%=chipTracContext%>/jsp/includes/images/printer_icon_small.gif" BORDER="0"></A>
        </TD>
    </TR>
    <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
    <%
        int startingWWNumber = 0;
        try
        {
            startingWWNumber = Integer.parseInt (request.getParameter ( "startingWWNumber" ));
        } catch ( NumberFormatException e ){}
        int wwYear = Integer.parseInt ( request.getParameter ( "wwYear" ) );
        String noOfWeeksStr = request.getParameter ("noOfWeeks");
        int noOfWeeks = 13;
        if( noOfWeeksStr != null && !noOfWeeksStr.trim().equalsIgnoreCase( "0" ) )
        {
            try
            {
                noOfWeeks = Integer.parseInt( noOfWeeksStr );
            }
            catch( Exception e )
            {
                 noOfWeeks = 13;
            }
        }
        int[] allWeekTotalQty = new int[noOfWeeks];
    %>
    <TR BGCOLOR="#DEE1E2" ALIGN = "CENTER" padding="0">
        <TD WIDTH="9%" NOWRAP style="border-width:1px;" CLASS="tdThinBorderLTB"><FONT CLASS='NArialL'><FONT COLOR="#000000">Vendor Name</FONT></FONT></TD>
        <TD WIDTH="9%" NOWRAP style="border-width:1px;" CLASS="tdThinBorderLTB"><FONT CLASS='NArialL'><FONT COLOR="#000000">Part Number</FONT></FONT></TD>
        <%
            int wwNumber = startingWWNumber;
            for (int k = 0; k < noOfWeeks; k++) {
                if (wwNumber == 53 && k > 0) {
                    Calendar cal = Calendar.getInstance();
                    cal.set(wwYear, Calendar.DECEMBER, 31);
                    WorkWeek workWeek = WorkWeek.getWorkWeekInstance(cal.getTime());
                    if (workWeek.getCurrentWWNumber() != wwNumber) //Work week 53 not present
                    {
                        wwNumber = 1;
                        wwYear = wwYear + 1;
                    }
                } else if (wwNumber > 53) {
                    wwNumber = 1;
                    wwYear = wwYear + 1;
                }
                if (k != 25) {
        %>
                <TD WIDTH="9%" style="border-width:1px;" CLASS='<%=(k==(noOfWeeks-1))?"tdThinBorderLRTB":"tdThinBorderLTB"%>'><FONT CLASS='NArialL'><FONT COLOR="#000000"><%= "WW-" + wwNumber%></FONT></FONT></TD>
        <%
                }
                else
                {
        %>
                <TD WIDTH="9%" style="border-width:1px;" CLASS="tdThinBorderLRTB"><FONT CLASS='NArialL'><FONT COLOR="#000000"><%= "WW-" + wwNumber + " to ~"%></FONT></FONT></TD>
        <%
                }
                wwNumber++;
            }
        %>
    </TR>
    <logic:iterate name="wipFlush" id="vendor" scope="session" type="com.scalar.chiptrack.operations.reports.WipFlushByDate">
        <TR BGCOLOR="#F2DBDB" ALIGN = "RIGHT">
            <TD WIDTH="9%" NOWRAP ALIGN="LEFT" style="border-width:1px;" CLASS="tdThinBorderLB"><FONT CLASS='NArialL'><bean:write name="vendor" property="vendor"/></FONT></TD>
            <TD WIDTH="9%" NOWRAP ALIGN="LEFT" style="border-width:1px;" CLASS="tdThinBorderLB"><FONT CLASS='NArialL'>&nbsp;</FONT></TD>
        <%
            for( int i = 0; i < noOfWeeks; i++ )
            {
                allWeekTotalQty[i] += vendor.getAllWeekQty()[i];
        %>
                <TD WIDTH="9%" style="border-width:1px;" CLASS='<%=(i==(noOfWeeks-1))?"tdThinBorderLBR":"tdThinBorderLB"%>'><FONT CLASS='NArialL'><%=vendor.getFormattedAllWeekQty()[i]%></FONT></TD>
        <%
            }
        %>
        </TR>
        <logic:iterate name="vendor" property="childMap" id="baseProductMap">
             <bean:define name="baseProductMap" property="value" id="baseProduct" type="com.scalar.chiptrack.operations.reports.WipFlushByDate"/>
             <TR BGCOLOR="#CDCEE9" ALIGN = "RIGHT">
                <TD WIDTH="9%" NOWRAP ALIGN="LEFT" style="border-width:1px;" CLASS="tdThinBorderLB"><FONT CLASS='NArialL'>&nbsp;</FONT></TD>
                <TD WIDTH="9%" NOWRAP ALIGN="LEFT" style="border-width:1px;" CLASS="tdThinBorderLB"><FONT CLASS='NArialL'><bean:write name="baseProduct" property="partNumber"/></FONT></TD>
                 <%
                    for( int i = 0; i < noOfWeeks; i++ )
                    {
                %>
                        <TD WIDTH="9%" style="border-width:1px;" CLASS='<%=(i==(noOfWeeks-1))?"tdThinBorderLBR":"tdThinBorderLB"%>'><FONT CLASS='NArialL'><%=baseProduct.getFormattedAllWeekQty()[i]%></FONT></TD>
                <%
                    }
                %>
            </TR>
            <logic:iterate name="baseProduct" property="childMap" id="productMap">
                <bean:define name="productMap" property="value" id="product" type="com.scalar.chiptrack.operations.reports.WipFlushByDate"/>
                 <TR BGCOLOR="#CDCEE9" ALIGN = "RIGHT">
                    <TD WIDTH="9%" NOWRAP ALIGN="LEFT" style="border-width:1px;" CLASS="tdThinBorderLB"><FONT CLASS='NArialS'>&nbsp;</FONT></TD>
                    <TD WIDTH="9%" NOWRAP ALIGN="LEFT" style="border-width:1px;" CLASS="tdThinBorderLB"><FONT CLASS='NArialS'><bean:write name="product" property="partNumber"/></FONT></TD>
                     <%
                        for( int i = 0; i < noOfWeeks; i++ )
                        {
                    %>
                            <TD WIDTH="9%" style="border-width:1px;" CLASS='<%=(i==(noOfWeeks-1))?"tdThinBorderLBR":"tdThinBorderLB"%>'><FONT CLASS='NArialS'><%=product.getFormattedAllWeekQty()[i]%></FONT></TD>
                    <%
                        }
                    %>
                </TR>
            </logic:iterate>
        </logic:iterate>
    </logic:iterate>
        <TR BGCOLOR="#DEE1E2" ALIGN="RIGHT">
            <TD WIDTH="9%" NOWRAP ALIGN="LEFT" style="border-width:1px;" CLASS="tdThinBorderLB"><FONT CLASS='NArialL' STYLE="COLOR:BLACK">Grand Total</FONT></TD>
            <TD WIDTH="9%" NOWRAP ALIGN="LEFT" style="border-width:1px;" CLASS="tdThinBorderLB">&nbsp;</TD>
            <%
                for( int i = 0; i < noOfWeeks; i++ )
                {
            %>
                    <TD WIDTH="9%" style="border-width:1px;" CLASS='<%=(i==(noOfWeeks-1))?"tdThinBorderLBR":"tdThinBorderLB"%>'><FONT CLASS='NArialL' STYLE="COLOR:BLACK"><%=StringUtils.getUSNumberFormat(allWeekTotalQty[i])%></FONT></TD>
            <%
                }
            %>
        </TR>
    </TABLE>
</TABLE>
</BODY>
</logic:present>
<logic:notPresent  name="wipFlush" scope="session">
<BODY bgcolor='ffffff' marginheight='0' marginwidth='0' topmargin='0' leftmargin='0' >
    <TABLE cellpadding='0' cellspacing='0' bgcolor='FDF5E6' border="0" width="100%"  height="100%" align=center>
        <TR>
            <TD>
                <TABLE align="center" border="0" width="40%" bgcolor="#FDF5E6">
                    <TR><TD>&nbsp;</TD></TR>
                    <TR><TD align="center" ><font class="NArialL" ><font color="red"><b>Session has been time out , Please close this window and login again.</b></font></font></TD></TR>
                    <TR><TD>&nbsp;</TD></TR>
                    <TR><TD align="center" ><a href="javascript:window.close();"><font class='NArialL'>[Close this window]</font></a></TD></TR>
                </TABLE>
            </TD>
       </TR>
       <TR><TD>&nbsp;</TD></TR>
    </TABLE>
</BODY>
</logic:notPresent>

</html:html>
